package com.zy.yun.base.util;

import org.apache.commons.codec.digest.DigestUtils;


/**
  * @Author: 王彦委
  * @Description: md5加密
  * @Date: 21:23 2019/10/19
  */
public class Md5Utils
{
  public static void main(String[] args)
{
//	new Md5Utils().md5salt();
}
  
  
  public  void  md5(){
	  String keyword="i love you";
	  String s=DigestUtils.md5Hex(keyword);
      System.out.println(s);
  }
	
/**
  * @Author: 王彦委
  * @Description: 根据密码和盐值，获取加密后的密码值
  * @Date: 21:26 2019/10/19
  */
  public static String md5salt(String password,String salt)
  {
	  String md5=DigestUtils.md5Hex(password);
	  System.out.println("md5加密后："+"\n"+md5);
	  String md5salt=md5PlusSalt(salt);
	  System.out.println("加盐后："+"\n"+md5salt);
//	  String word= md5MinusSalt(md5salt);

	  return md5salt;
  }
  
  
  public static String md5PlusSalt(String keyword)
  {
	  String md5=DigestUtils.md5Hex(keyword);
	  char[]cArray=md5.toCharArray();
	  for(int i=0;i<cArray.length;i++)
	  {
		  if(cArray[i]>=48&&cArray[i]<=57)
		  {
			  cArray[i]=(char)(105-cArray[i]);

		  }
	  }
	 return  "".valueOf(cArray);

  }

  
  public static String md5MinusSalt(String md5)
  {
	  char[]cArray=md5.toCharArray();
	  for(int i=0;i<cArray.length;i++)
	  {
		  if(cArray[i]>=48&&cArray[i]<=57)
		  {
			  cArray[i]=(char)(105-cArray[i]);

		  }
	  }
	 return  "".valueOf(cArray);

  }
}

